﻿using Abp;
using Abp.Domain.Services;
using Abp.Notifications;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Partner.Surround.Notifications
{
    /// <summary>
    /// 消息通知发布实例
    /// </summary>
    public class AppNotifier : DomainService, IAppNotifier
    {
        #region 初始化
        private readonly INotificationPublisher _notificationPublisher;

        public AppNotifier(INotificationPublisher notificationPublisher)
        {
            _notificationPublisher = notificationPublisher;
        }
        #endregion

        #region 消息发送
        public async Task SendMessageAsync(UserIdentifier user, string message, NotificationSeverity severity = NotificationSeverity.Info)
        {
            await _notificationPublisher.PublishAsync(
                AppNotificationNames.SimpleMessage,
                new MessageNotificationData(message),
                severity: severity,
                userIds: new[] { user }
            );
        }
        #endregion

        #region 任务提醒
        public async Task NewTaskAsync(string message, NotificationSeverity severity = NotificationSeverity.Info)
        {
            await PublishMessage(AppNotificationNames.NewTask, message);
        }
        #endregion

        #region 辅助方法
        private async Task PublishMessage(string appNotificationName, string message)
        {
            await _notificationPublisher.PublishAsync(appNotificationName, new MessageNotificationData(message));
        }
        #endregion
    }
}
